<?
	 layout("/inc/win_layout.html",{title:sysTitle}){
    ?>
	<link rel="stylesheet" href="static/uploadify/uploadify.css" type="text/css"></link>
	<script type="text/javascript" src="static/uploadify/jquery.uploadify.min.js"></script>
    <script type="text/javascript" src="static/utf8-jsp/ueditor.config.js"></script>
	<script type="text/javascript" src="static/utf8-jsp/ueditor.all.js"></script>
	<script type="text/javascript" src="static/utf8-jsp/lang/zh-cn/zh-cn.js"></script>
	<script type="text/javascript" src="static/utf8-jsp/third-party/video-js/video.js"></script>
	<script type="text/javascript" src="static/My97DatePicker/WdatePicker.js"></script>
	<div class="panel panel">
	<div class="panel-body pan" style="height: 550px; overflow: auto;">
		<div class="clearfix" style="margin-bottom: 10px;">
			<input id="id" type="hidden" class="form-control" value="" />
			<div class="col-lg-6"
				style="width: 100%; float:left; margin-right:-20px; display:inline;">
				<label for="inputUsername" class="col-md-3 control-label">标题<span
						class='require'>*</span> 
				</label>
				<div class="col-md-9">
					<div class="input-icon">
						<input id="title" type="text" class="form-control" value="" />
					</div>
				</div>
			</div>
		</div>
		<div id="showSeparator"  class="clearfix"  style="margin-bottom: 10px;">
			<input id="id" type="hidden" class="form-control" value="" />
			<div class="col-lg-6"
				style="width: 100%; float:left; margin-right:-20px; display:inline;">
				<label for="inputUsername" class="col-md-3 control-label">摘要<span
						class='require'>*</span> 
				</label>
				<div class="col-md-9">
					<div class="input-icon">
						<textarea id="summary" rows="2" cols="20" class="form-control"></textarea>
					</div>
				</div>
			</div>
		</div>
		<div  class="clearfix"  style="margin-bottom: 10px;">
			<div class="col-lg-6 clearfix"
				style="width: 395px; float:left; margin-right:-20px;display:inline;">
				<label for="inputUsername" class="col-md-3 control-label">封面图片<span
						class='require'>*</span> </label>
				<div class="col-md-9 clearfix">
					<div>
						<div style="display:inline " id="single"></div>
						<input type="button" class="btn btn-primary" style="width: 70px;height: 30px;padding: 0;background-color: #4cae4c;border-color: #4cae4c;" onclick="upImages()" value="上传图片"  />
						<textarea id="uploadImage" name="uploadImage"></textarea>
						<input id="coverImg" type="hidden" class="form-control" value="" />
					</div>
				</div>
			</div>
			<div class="col-lg-6 clearfix"
				style="width: 395px; float:left; margin-right:-20px; display:inline;">
				<label for="inputUsername" class="col-md-3 control-label">发布时间<span
						class='require'>*</span> 
				</label>
				<div class="col-md-9 clearfix">
					<div class="input-icon">
						<input id="submitTime" type="text" class="form-control" value="" onclick="WdatePicker({skin:'whyGreen',dateFmt:'yyyy-MM-dd HH:mm:ss'})" />
					</div>
				</div>
			</div>
			<div class="col-lg-6 clearfix"
				style="width: 395px; float:left; margin-right:-20px; display:inline;">
				<label for="inputUsername" class="col-md-3 control-label">来源<span
						class='require'>*</span> 
				</label>
				<div class="col-md-9 clearfix">
					<div class="input-icon">
						<input id="source" type="text" class="form-control" value="" />
					</div>
				</div>
			</div>
			<div class="col-lg-6 clearfix"
				style="width: 395px; float:left; margin-right:-20px; display:inline;">
				<label for="inputUsername" class="col-md-3 control-label">发布者<span
						class='require'>*</span> 
				</label>
				<div class="col-md-9 clearfix">
					<div class="input-icon">
						<input id="submitUser" type="text" class="form-control" value="" />
					</div>
				</div>
			</div>
			<div class="col-lg-6 clearfix"
				style="width: 395px; float:left; margin-right:-20px; display:inline;">
				<label for="inputUsername" class="col-md-3 control-label">状态<span
						class='require'>*</span> 
				</label>
				<div class="col-md-9 clearfix">
					<div class="input-icon">
						<select id="status" class="form-control">
							<option value="0">未发布</option>
							<option value="1">已发布</option>
						</select>
					</div>
				</div>
			</div>
		
		
		</div>
	
		<div id="showSeparator"  class="clearfix"  style="margin: 0px auto;margin-bottom: 30px;width: 740px; height: 500px">
			<label for="inputUsername" class="col-md-3 control-label">正文<span
						class='require'>*</span> 
			</label>
			<div class="col-md-12">
				<div class="input-icon">
					<script id="containerText" name="containerText" type="text/plain" ></script>
					 <script type="text/javascript">
				        var text = UE.getEditor('containerText',{ initialFrameHeight:370 });
				    </script>
				</div>
			</div>
		</div>
	</div>
</div>
<?} ?>
<script>
	var index1 = window.parent.getlay();
	var _editor;
	var classesIds = "";
	$(function() {
		if (index1 != 0) {
			$.ajax({
				type : "post",
				url : "uploadBaikeNews.do",
				data : {
					"id" : index1,
				},
				dataType : "json",
				async : false,
				success : function(data) {
					
					$("#title").val(data[0].title);
					$("#id").val(data[0].id);
					$("#summary").val(data[0].summary);
					$("#coverImg").val(data[0].coverImg);
					$("#submitTime").val(data[0].submitTime);
					$("#source").val(data[0].source);
					$("#submitUser").val(data[0].submitUser);
					$("#status").val(data[0].status);
					$("#containerText").html(data[0].text);
					$("#single").html("<img src='"+data[0].coverImg+"' width='30' height='30'/>");
					//selected("classesIds",data[0].classesIds);
					
				},
				error : function(data) {
					alert("请求失败");
				}
			});
		}
		 _editor = UE.getEditor('uploadImage');
	    _editor.ready(function (){
	        //设置编辑器不可用(事实上不可以设置不可用...所以注释掉,以观后效)
	        _editor.setDisabled();
	        //隐藏编辑器,因为只使用上传功能
	        _editor.hide();
	        //侦听图片上传
	  	 	_editor.addListener('beforeInsertImage',function(t,arg){
	  	 			for(var i=0;i<arg.length;i++){
	  	 				var urlPath = arg[i].src;
	  	 				$("#coverImg").val(urlPath);
						$("#single").html("<a href="+urlPath+" download='w3logo'><img src='"+urlPath+"' width='30' height='30' /></a>");
	  	 			}
	        });
	        //侦听文件上传
		   	 _editor.addListener('afterUpfile',function(t,arg){
		   	 	
		   	 });
	   }); 
	});
	//上传图片
	function upImages() {
		var myFiles = _editor.getDialog("insertimage");
	  		myFiles.open();
	   
	}
	function save() {
		var saveText = UE.getEditor('containerText');
		//获取html内容
		var ueditortext = saveText.getContent();
		if($.trim($("#title").val()).length<1) {
    	        	alert('标题不能为空！');
    	        	return null;
    	    }
		 if($.trim($("#summary").val()).length<1) {
    	        	alert('摘要不能为空！');
    	        	return null;
    	    }
		 if($.trim($("#coverImg").val()).length<1) {
    	        	alert('封面图片不能为空！');
    	        	return null;
    	    }
		 if($.trim($("#submitTime").val()).length<1) {
    	        	alert('发布时间不能为空！');
    	        	return null;
    	    }
		 if($.trim($("#source").val()).length<1) {
    	        	alert('来源不能为空！');
    	        	return null;
    	    }
		 if($.trim($("#submitUser").val()).length<1) {
    	        	alert('发布者不能为空！');
    	        	return null;
    	    }
		 if($.trim(ueditortext).length<1) {
    	        	alert('正文不能为空！');
    	        	return null;
    	    }
		$.ajax({
			type : "post",
			url : "addBaikeNews.do",
			data : {
				"title":$("#title").val(),
				"summary":$("#summary").val(),
				"coverImg":$("#coverImg").val(),
				"submitTime":$("#submitTime").val(),
				"source":$("#source").val(),
				"submitUser":$("#submitUser").val(),
				"status":$("#status").val(),
				"id":$("#id").val(),
				"text":ueditortext,
			},
			dataType : "json",
			traditional : true,
			success : function(data) {
				var index = parent.layer.getFrameIndex(window.name);
				window.parent.demo(1);
				parent.layer.msg('提交成功');
				parent.layer.close(index);
			},
			error : function(data) {
				alert("请求失败");
			}
		});
	}

</script>